//
//  TestTableInputCell.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2022/1/22.
//  Copyright © 2022 CocoaPods. All rights reserved.
//

import UIKit
import CooperSwift
import RxSwift

class TestTableInputCellModel: NSObject, TableCellConfigProtocol, FormModelProtocol  {

    typealias TargetType = UITextField
    
    var model: Any?
    
    required init(_ model: Any?) {
        self.model = model
    }
    
    func cellCls() -> UITableViewCell.Type {
        return TestTableInputCell.self
    }
    
    func cellOnce(_ cell: UITableViewCell) {
        print("cell Once")
    }
    
    func cellEvery(_ cell: UITableViewCell) {
        print("cell Every")
    }
    
}


class TestTableInputCell: UITableViewCell {
    
    @IBOutlet weak var titleLB: UILabel!
   
    @IBOutlet weak var tf: UITextField!
    
    let bag = DisposeBag()
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        LimitInputHelper.tf(tf, rules: [.phone], bag: bag) { [weak self] in
            guard let `self` = self else { return }
            guard let model = self.info as? FormModelProtocol else { return }
            model.keyValue = $0
        }
    }
    
    override func bindTo(_ info: Any?) {
        super.bindTo(info)
        guard let cellModel = info as? TestTableInputCellModel else { return }
        if let value = cellModel.keyValue {
            tf.text
        }
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
